package com.example.lean;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    public static final String ACTION_SECOND = "com.example.lean.intent.action.SECOND";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void myClick(View v) {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, 100);
    }

    //第一个参数：这个整数requestCode提供给onActivityResult，是以便确认返回的数据是从哪个Activity返回的。这个requestCode和startActivityForResult中的requestCode相对应。
    //第二个参数：这整数resultCode是由子Activity通过其setResult()方法返回。
    //第三个参数：一个Intent对象，带有返回的数据
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent it) {
        super.onActivityResult(requestCode, resultCode, it);
        if (resultCode == RESULT_OK && requestCode == 100) {
            Bundle bdl = it.getExtras();
            Bitmap bmp = (Bitmap)bdl.get("data");
            ImageView imv= findViewById(R.id.imageView);
            imv.setImageBitmap(bmp);
        } else {
            Toast.makeText(this, "没有拍到照片", Toast.LENGTH_LONG).show();
        }
    }
}